'''
外勤管理页面测试
'''
from selenium.webdriver.common.by import By

from Lib.base.page_object.attendance.fieldword import Fieldwork
import allure
from Lib.common.assert_class import AssertClass
import pytest
from Lib.common.get_data_by_mysql import MysqlAssert


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestFieldwork.assertClass = AssertClass(login)
    TestFieldwork.fieldwork = Fieldwork(login)


@allure.feature("外勤管理测试")
class TestFieldwork:

    @allure.title('筛选外勤列表')
    def test_fieldwork_list(self, login):
        '''
        根据筛选条件筛选加班列表
        :param login:
        :return:
        '''
        with allure.step('根据审批状态查看外勤列表'):
            # 调用页面操作方法
            self.fieldwork.fieldwork_list_by_status()
            # 断言
            assert_args = (By.XPATH, '//tbody/tr/td[10]//span[text()="已通过"]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='已通过')
        with allure.step('根据时间筛选外勤列表'):
            # 调用页面操作方法
            self.fieldwork.fieldwork_list_by_time()
            # 断言
            assert_args1 = (By.XPATH, '//tbody/tr[1]/td[9]//span')
            assert_args2 = (By.XPATH, '//tbody/tr[2]/td[9]//span')
            self.assertClass.make_assert_by_compare_time(args1=assert_args1, args2=assert_args2)

    @allure.title('搜索外勤并查看详情')
    def test_fieldwork_search_and_detail(self):
        '''
        搜索外勤、并查看外勤详情
        :return:
        '''
        with allure.step('根据关键词搜索外勤'):
            self.fieldwork.fieldwork_search()
            assert_args = (By.XPATH, '//tbody/tr/td[2]//span[text()="申请人kb"]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='申请人kb')
        with allure.step('查看外勤详情'):
            self.fieldwork.fieldwork_detail()
            assert_args = (By.XPATH, '//div[@class="fieldwork-container"]//div[contains(text(), "已通过")]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='已通过')


if __name__ == '__main__':
    # pytest.main(
    #     ['-v', '-s', './fieldwork_test.py::TestFieldwork'])
    # pytest.main(['-v', './business_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
    print(TestFieldwork.__dict__)
